package com.wll.store.user.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wll.store.user.dto.AddrPageInfo;
import com.wll.store.user.entity.Address;
import com.wll.store.user.mapper.AddressMapper;
import com.wll.store.user.service.AddressService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sdx2009
 * @since 2022-09-06
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    /**
     * 获取address分页信息
     * @param addrPageInfo
     * @return
     */
    @Override
    public Page<Address> getAddrPage(AddrPageInfo addrPageInfo) {
        Page<Address> page = new Page<>();
        //每页多少数据
        page.setSize(addrPageInfo.getPageSize());
        //第几页
        page.setCurrent(addrPageInfo.getPageNumber());
        return this.page(page);
    }

    @Override
    public Boolean addAddr(Address address) {
        Address addr = new Address();
        addr.setAddrusername(address.getAddrusername());
        addr.setDetailaddr(address.getDetailaddr());
        addr.setAddrphone(address.getAddrphone());
        addr.setAddrtype(address.getAddrtype());
        return this.save(addr);
    }

    @Override
    public Boolean updateAddrInfoByname(Address addressInfo) {
        Address address = new Address();
        address.setAddrusername(addressInfo.getAddrusername());
        address.setAddrtype(addressInfo.getAddrtype());
        address.setDetailaddr(addressInfo.getDetailaddr());
        address.setAddrphone(addressInfo.getAddrphone());
        UpdateWrapper<Address> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",addressInfo.getId());
        return this.update(address,wrapper);
    }

    @Override
    public Boolean deleteAddrInfoById(Integer id) {
        return this.removeById(id);
    }


}
